<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>信息将显示在这里</div> <!-- 添加一个 div 元素 -->
  <script>

    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://127.0.0.1:30001/api?age=20');
    xhr.send();

    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                try {
                    const response = JSON.parse(xhr.responseText);
                    if (response) {
                        const div = document.querySelector("div");
                        div.textContent = `我是${response.name || '未知'}，${response.age || '未知'}岁，我有${response.car || '未知'}`;
                    } else {
                        console.error("响应为空");
                    }
                } catch (error) {
                    console.error("解析 JSON 失败:", error);
                }
            } else {
                console.error("请求失败，状态码：" + xhr.status);
            }
        }
    }

    
  </script>
    
</body>
</html>
